package com.ruoyi.web.controller.message;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.AliSmsUtils;
import com.ruoyi.system.domain.message.Message;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/message")
public class MessageController extends BaseController {

	@PostMapping(value = "/sendMessage")
	public AjaxResult sendMessage(@RequestBody Message message) {

		try {
			//平台代预定房间成功后短信
			if(StrUtil.equals(message.getMessageType(), "booking_success")){
				AliSmsUtils.bookingSuccessMessage(message.getMobile(), message.getName(), message.getBookingInfo());
			}
			//客户到店，平台支付成功后提醒客户此次消费用券
			if(StrUtil.equals(message.getMessageType(), "platform_pay_success")){
				AliSmsUtils.platformPaySuccessMessage(message.getMobile(), message.getName(), message.getUseTicket(),message.getLeftTicket());
			}
			//提醒发货短信
			if(StrUtil.equals(message.getMessageType(), "notice_send")){
				AliSmsUtils.noticeSendMessage(message.getMobile(),message.getName(),message.getGoodsInfo(),message.getBuyNum(),message.getAddress(),message.getPhone());
			}
			return AjaxResult.success();
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error();
		}

	}


}
